Cover TOC Chap Prev Chap Prev Fig Next Fig Next Chap

Chapter 9: Sensing Viewer Actions

../ch09/09fig09.gif
Figure 9.9

A desk lamp that can be adjusted using nested sensors.

09fig09.wrl
Click on the image to view the VRML scene.

#VRML V2.0 utf8
# The VRML 2.0 Sourcebook
# Copyright (c) 1997
# Andrea L. Ames, David R. Nadeau, and John L. Moreland
Group {
  children [
  # Lamp
    DEF MoveLamp PlaneSensor { },
    DEF Lamp Transform {
      children [
      # Lamp base
        Shape {
          appearance DEF White Appearance {
            material Material { }
          }
          geometry Cylinder {
            radius 0.1
            height 0.01
          }
        },
      # Base - First arm joint
        Group {
          children [
            DEF MoveFirstArm SphereSensor {
              offset 1.0 0.0 0.0 -0.7
            },
            DEF FirstArm Transform {
              translation 0.0 0.15 0.0
              rotation    1.0 0.0 0.0  -0.7
              center      0.0 -0.15 0.0
              children [
              # Lower arm
                DEF LampArm Shape {
                  appearance USE White
                  geometry Cylinder {
                    radius 0.01
                    height 0.3
                  }
                },
              # First arm - second arm joint
                Group {
                  children [
                    DEF MoveSecondArm SphereSensor {
                      offset 1.0 0.0 0.0 1.9
                    },
                    DEF SecondArm Transform {
                      translation 0.0 0.3 0.0
                      rotation  1.0 0.0 0.0  1.9
                      center    0.0 -0.15 0.0
                      children [
                      # Second arm
                        USE LampArm,
                      # Second arm - shade joint
                        Group {
                          children [
                            DEF MoveLampShade SphereSensor {
                              offset 1.0 0.0 0.0 -1.25
                            },
                            DEF LampShade Transform {
                              translation 0.0 0.075 0.0
                              rotation  1.0 0.0 0.0  -1.25
                              center    0.0 0.075 0.0
                              children [
                              # Shade
                                Shape {
                                  appearance USE White
                                  geometry Cone {
                                    height 0.15
                                    bottomRadius 0.12
                                    bottom FALSE
                                  }
                                },
                              # Light bulb
                                Transform {
                                  translation 0.0 -0.05 0.0
                                  children Shape {
                                    appearance USE White
                                    geometry Sphere {
                                      radius 0.05
                                    }
                                  }
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}
ROUTE MoveLamp.translation_changed   TO Lamp.set_translation
ROUTE MoveFirstArm.rotation_changed  TO FirstArm.set_rotation
ROUTE MoveSecondArm.rotation_changed TO SecondArm.set_rotation
ROUTE MoveLampShade.rotation_changed TO LampShade.set_rotation